package com.tzx.socket;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * Created by STVEN0KING
 * Date: 2016/10/10.
 * Description:
 */
public class UdpSocketServer {
    public static void main(String[] args) {
        ServerReceviedByUdp();
    }

    public static void ServerReceviedByUdp() {
        DatagramSocket socket;
        try {
            socket = new DatagramSocket(1989);
            byte data[] = new byte[1024 * 4];
            DatagramPacket packet = new DatagramPacket(data, data.length);
            socket.receive(packet);
            String result = new String(packet.getData(), packet.getOffset(), packet.getLength());
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
